/**
 * 	write on 2005-10-2 9:33:46.
 */
package org.nanhill.commons.math;

import java.math.BigInteger;

/**
 * @author alin
 * 
 */
public class Factorial {
	public static String getBigFactorial(int n) throws Exception {
		if (n < 0) {
			throw new IllegalArgumentException("The input argument: [" + n
					+ "] must be zero or positive number!");
		}
		if (n == 0 || n == 1) {
			return "1";
		}
		BigInteger result = new BigInteger("1");
		for (int i = 1; i <= n; i++) {
			BigInteger b = new BigInteger(Integer.toString(i));
			result = result.multiply(b);
		}
		return result.toString();
	}

	public static long getSmallFactorial(int n) {
		long result = 1;
		if (n == 0 || n == 1) {
			result = 1;
		} else {
			for (int i = 1; i <= n; i++) {
				result = result * i;
			}
		}
		return result;
	}
}
